//
//  HJDBannerTwoViewController.m
//  JYHospital
//
//  Created by 胡金东 on 16/5/16.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "HJDBannerTwoViewController.h"
#import "BSMacros.h"
#import "AFNetworking.h"
#import "MJExtension.h"

@interface HJDBannerTwoViewController ()<UIScrollViewDelegate>

//背景
@property (nonatomic,strong) UIImageView *imageBg;


@property (nonatomic,strong)UIScrollView *scroll;
//图片
@property (nonatomic,strong) UIImageView *imageV ;
//标题
@property (nonatomic,strong) UILabel *lblTitle ;

@property (nonatomic,strong) UILabel *publishTime;
//发布时间
@property (nonatomic,strong) UILabel * timeC;
//发布内容
@property (nonatomic,strong) UILabel *publishContent ;
//附录一
@property (nonatomic,strong) UILabel *onelbl;
//附录一内容
@property (nonatomic,strong) UILabel *oneClbl;
//附录二
@property (nonatomic,strong) UILabel *twolbl;
//附录二内容
@property (nonatomic,strong) UILabel *twoClbl;
//附录三
@property (nonatomic,strong) UILabel *threelbl ;
//附录三内容
@property (nonatomic,strong) UILabel *threeClbl ;






@end

@implementation HJDBannerTwoViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"活动";
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:19],
       NSForegroundColorAttributeName:[UIColor getColorWithHexNumber:@"848484"]}];

    self.view.backgroundColor = [UIColor getColorWithHexNumber:@"F1F0EE"];
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(backBtnClick) image:@"︿" HighImage:nil];
            NSString *Id = [[NSUserDefaults standardUserDefaults]stringForKey:@"BannerID1"];
//
//    NSLog(@"iddddd-----%@",Id);
            NSString *url = @"/app/activyEdit.do";
            NSString *path = [Hurl stringByAppendingString:url];
            AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
            NSMutableDictionary *params = [NSMutableDictionary dictionary];
            params[@"id"]= Id;
            [mgr POST:path parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
    
            } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSDictionary *info =(NSDictionary *)responseObject;
              NSString *banner = info[@"resultMap"];
                self.TwoModel = [HJDBannerTwoModel mj_objectWithKeyValues:banner];
                [self setUplabel];

//                NSLog(@"idididi---------%@",responseObject);
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                [MBProgressHUD showError:@"服务器升级，请稍后再试"];
//                NSLog(@"error%@",error);
            }];
    

    
    
    
    
    [self setUpContent];
    
//    [self setUplabel];
}
//返回
-(void)backBtnClick{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)setUpContent{

    self.scroll = [[UIScrollView alloc]initWithFrame:
                   [UIScreen mainScreen].bounds];
    self.scroll.delegate = self;
    //    self.scroll.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"首页背景"]];
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.scroll.showsVerticalScrollIndicator = YES;//垂直移动
    self.scroll.showsHorizontalScrollIndicator = NO;//水平移动
    //上下滑动
//    self.scroll.contentSize = CGSizeMake(HJDWidth,1500 ) ;
    
    
    [self.view addSubview: self.scroll];
    UIView *viewBg = [[UIView alloc]initWithFrame:CGRectMake(12,10,HJDWidth - 24 , 2092/2)];
    self.imageBg = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,HJDWidth - 24 , 2092/2)];
    self.imageBg.image = [UIImage imageNamed:@"活动背景"];
    [viewBg addSubview:self.imageBg];
    [self.scroll addSubview:viewBg];
//    
//    CGFloat publishTimeX = 10;
//    CGFloat publishTimeY = CGRectGetMaxY(self.lblTitle.frame)+15;
//    
//    self.publishTime = [[UILabel alloc]init];
//    self.publishTime.text = @"发布时间 ：";
//    self.publishTime.textColor = [UIColor getColorWithHexNumber:@"A4A4A4"];
//    self.publishTime.font = [UIFont systemFontOfSize:13];
//    CGSize publishTimeSize = [_publishTime.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.publishTime.font,NSFontAttributeName, nil]];
//    self.publishTime.frame = (CGRect){{publishTimeX,publishTimeY},publishTimeSize};
//    [self.imageBg addSubview:self.publishTime];
    
   

    
}

-(void)setUplabel
{
    self.imageV = [[UIImageView alloc]initWithFrame:CGRectMake(10, 30, HJDWidth - 24-20,125 )];
    NSString *url = [NSString stringWithFormat:@"%@/%@",headImageUrl,self.TwoModel.headUrl];
    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
     self.imageV.image = [image stretchableImageWithLeftCapWidth:image.size.width*0.5 topCapHeight:image.size.height*0.5];
    
    [self.imageBg addSubview:self.imageV];
    
    
    CGFloat lblTitleX = 10 ;
    CGFloat lblTitleY = CGRectGetMaxY(self.imageV.frame)+15;
    CGFloat lblTitleW = HJDWidth - 44;
    self.lblTitle = [[UILabel alloc]init];
    self.lblTitle.numberOfLines = 0;
       self.lblTitle.text = self.TwoModel.head;
    //    NSLog(@"------2222%@",self.TwoModel.head);
    //    self.lblTitle.text = @"算了算了看电视了老师发来撒拉拉风啦啦啦发垃圾了睡觉啦放假了撒娇";
//    self.lblTitle.text = [NSString stringWithFormat:@"%@",self.TwoModel.head];
    self.lblTitle.textColor = [UIColor getColorWithHexNumber:@"323232"];
    self.lblTitle.font = [UIFont systemFontOfSize:19];
    
    CGRect lblTitleRect = [_lblTitle.text boundingRectWithSize:CGSizeMake(lblTitleW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.lblTitle.font,NSFontAttributeName, nil] context:nil];
    self.lblTitle.frame = (CGRect){{lblTitleX,lblTitleY},lblTitleRect.size};
    [self.imageBg addSubview:self.lblTitle];
    
    
    
    CGFloat timeCX = CGRectGetMaxX(self.publishTime.frame);
    CGFloat timeCY = CGRectGetMaxY(self.lblTitle.frame)+15;
    
    self.timeC = [[UILabel alloc]init];
    //    self.timeC.text = @"2016-07-26 09:01:55";
        self.timeC.text = self.TwoModel.createTime;
    
    self.timeC.text = [NSString stringWithFormat:@"   发布时间 ：%@",self.TwoModel.createTime];
    self.timeC.textColor = [UIColor getColorWithHexNumber:@"A4A4A4"];
    self.timeC.font = [UIFont systemFontOfSize:13];
    CGSize timeCSize = [self.timeC.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.timeC.font,NSFontAttributeName, nil]];
    self.timeC.frame = (CGRect){{timeCX,timeCY},timeCSize};
    [self.imageBg addSubview:self.timeC];
    
    CGFloat sourceX = 10;
    CGFloat sourceY = CGRectGetMaxY(self.timeC.frame)+5;
    UILabel *sourcelbl = [[UILabel alloc]init];
    sourcelbl.text = @"来源 ：";
    sourcelbl.textColor = [UIColor getColorWithHexNumber:@"A4A4A4"];
    sourcelbl.font = [UIFont systemFontOfSize:13];
    CGSize sourceSize = [sourcelbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:sourcelbl.font,NSFontAttributeName, nil]];
    sourcelbl.frame = (CGRect){{sourceX,sourceY},sourceSize};
    [self.imageBg addSubview:sourcelbl];
    
    CGFloat sourceCX = CGRectGetMaxX(sourcelbl.frame);
    CGFloat sourceCY = CGRectGetMaxY(self.timeC.frame)+5;
    UILabel *sourceClbl = [[UILabel alloc]init];
    sourceClbl.text = @"常州红房子";
    sourceClbl.textColor = [UIColor getColorWithHexNumber:@"A4A4A4"];
    sourceClbl.font = [UIFont systemFontOfSize:13];
    CGSize sourceCSize = [sourceClbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:sourceClbl.font,NSFontAttributeName, nil]];
    sourceClbl.frame = (CGRect){{sourceCX,sourceCY},sourceCSize};
    [self.imageBg addSubview:sourceClbl];

    
    CGFloat publishContentX = 10 ;
    CGFloat publishContentY = CGRectGetMaxY(self.timeC.frame)+60;
    CGFloat publishContentW = HJDWidth - 44;
    self.publishContent = [[UILabel alloc]init];
    self.publishContent.numberOfLines = 0;
//    self.publishContent.text = @"算了算了看电视了老师发来撒拉拉风啦啦啦发垃圾了睡觉啦放假了撒娇\n\n老师了放假了撒娇了就爱了福建垃圾了房间里送积分连接的垃圾分类是\n\n睡懒觉了撒娇垃圾分类是家乐福吉林省就浪费就垃圾了附件是了解了附近撒垃圾费";
    self.publishContent.text = self.TwoModel.content;
    self.publishContent.textColor = [UIColor getColorWithHexNumber:@"848484"];
    self.publishContent.font = [UIFont systemFontOfSize:15];
    
    CGRect publishContentRect = [self.publishContent.text boundingRectWithSize:CGSizeMake(publishContentW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.publishContent.font,NSFontAttributeName, nil] context:nil];
    self.publishContent.frame = (CGRect){{publishContentX,publishContentY},publishContentRect.size};
    [self.imageBg addSubview:self.publishContent];
    
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(self.publishContent.frame)+25, HJDWidth -44, 1)];
    img.image = [UIImage imageNamed:@"activeH"];
    [self.imageBg addSubview:img];

    
    
    CGFloat oneX = 10;
    CGFloat oneY = CGRectGetMaxY(self.publishContent.frame)+50;
    self.onelbl = [[UILabel alloc]init];
    self.onelbl.text = self.TwoModel.appendOne;
    self.onelbl.textColor = [UIColor getColorWithHexNumber:@"FE6077"];
    self.onelbl.font = [UIFont systemFontOfSize:15];
    CGSize oneSize = [self.onelbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.onelbl.font,NSFontAttributeName, nil]];
    self.onelbl.frame = (CGRect){{oneX,oneY},oneSize};
    [self.imageBg addSubview:self.onelbl];
    
    CGFloat oneCX = 10;
    CGFloat oneCY = CGRectGetMaxY(self.onelbl.frame)+10;
    self.oneClbl = [[UILabel alloc]init];
    self.oneClbl.text = self.TwoModel.contentOne;
    self.oneClbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
    self.oneClbl.font = [UIFont systemFontOfSize:15];
    CGSize oneCSize = [_oneClbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.oneClbl.font,NSFontAttributeName, nil]];
    self.oneClbl.frame = (CGRect){{oneCX,oneCY},oneCSize};
    [self.imageBg addSubview:self.oneClbl];
    
    CGFloat twoX = 10;
    CGFloat twoY = CGRectGetMaxY(self.oneClbl.frame)+20;
    self.twolbl = [[UILabel alloc]init];
    self.twolbl.text = self.TwoModel.appendTwo;
    self.twolbl.textColor = [UIColor getColorWithHexNumber:@"FE6077"];
    self.twolbl.font = [UIFont systemFontOfSize:15];
    CGSize twoSize = [_twolbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.twolbl.font,NSFontAttributeName, nil]];
    self.twolbl.frame = (CGRect){{twoX,twoY},twoSize};
    [self.imageBg addSubview:self.twolbl];
    
    CGFloat twoCX = 10;
    CGFloat twoCY = CGRectGetMaxY(self.twolbl.frame)+10;
    self.twoClbl = [[UILabel alloc]init];
    self.twoClbl.text = self.TwoModel.contentTwo;
    self.twoClbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
    self.twoClbl.font = [UIFont systemFontOfSize:15];
    CGSize twoCSize = [_twoClbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.twoClbl.font,NSFontAttributeName, nil]];
    self.twoClbl.frame = (CGRect){{twoCX,twoCY},twoCSize};
    [self.imageBg addSubview:self.twoClbl];
    
    CGFloat threeX = 10;
    CGFloat threeY = CGRectGetMaxY(self.twoClbl.frame)+20;
    self.threelbl = [[UILabel alloc]init];
    self.threelbl.text = self.TwoModel.appendThree;
    self.threelbl.textColor = [UIColor getColorWithHexNumber:@"FE6077"];
    self.threelbl.font = [UIFont systemFontOfSize:15];
    CGSize threeSize = [_threelbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.threelbl.font,NSFontAttributeName, nil]];
    self.threelbl.frame = (CGRect){{threeX,threeY},threeSize};
    [self.imageBg addSubview:self.threelbl];
    
    CGFloat threeCX = 10;
    CGFloat threeCY = CGRectGetMaxY(self.threelbl.frame)+10;
    self.threeClbl = [[UILabel alloc]init];
    self.threeClbl.text = self.TwoModel.contentThree;
    self.threeClbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
    self.threeClbl.font = [UIFont systemFontOfSize:15];
    CGSize threeCSize = [_threeClbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.threeClbl.font,NSFontAttributeName, nil]];
    self.threeClbl.frame = (CGRect){{threeCX,threeCY},threeCSize};
    [self.imageBg addSubview:self.threeClbl];
    
    
    
    self.scroll.contentSize = CGSizeMake(HJDWidth,CGRectGetMaxY(self.threeClbl.frame)+20) ;

}


@end
